package com.boarsoft.boar.soagov.svc.biz;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.boarsoft.boar.soagov.svc.SvcProtocolBiz;

@Component
@Aspect
public class SvcProtocolAspect {
	private static final Logger log = LoggerFactory.getLogger(SvcProtocolAspect.class);

	@Autowired
	protected SvcProtocolBiz svcProtocolBiz;

	// TODO 目前ProtocolInfo还没有删除功能，如果以后有了，这里也需要添加一个 ProtocolInfo删除功能切面

	/**
	 * 设置切面方法的映射
	 */
	@Pointcut("execution(* com.boarsoft.boar.soagov.svc.biz.SvcBizImpl.delete(String))")
	public void deleteSvc() {
		log.info("Point Cut com.boarsoft.boar.soagov.svc.biz.SvcBizImpl.delete");
	}

	/**
	 * svc_info的删除切面，删除svc_info时将svc_protocol相关的数据也一并删除
	 * 
	 * @param jp
	 */
	@After("deleteSvc()")
	public void onDeleteSvc(JoinPoint jp) {
		String svcId = (String) jp.getArgs()[0];
		log.info("After delete svcInfo {}, delete svc protocol of it", svcId);
		svcProtocolBiz.delete(svcId, null);
	}

}
